# -*- coding: utf-8 -*-
"""
Author:duan
Date: 2021/3/4 22:34
"""
import pika
import time

credentials = pika.PlainCredentials('guest', 'guest')
params = pika.ConnectionParameters(host='127.0.0.1', credentials=credentials)
connection = pika.BlockingConnection(params)
# 队列连接通道
channel = connection.channel()
# 声明队列
channel.queue_declare(queue='hello-123456', durable=True)

def callback(ch, method, properties, body):
    print("[*] Received %s" % body)
    time.sleep(10)
    print("[*] Message handle Done:%r" % body)
    ch.basic_ack(delivery_tag=method.delivery_tag)


channel.basic_consume(on_message_callback=callback,
                      queue='hello-123456',
                      auto_ack=False)

print("[*] Wait for messages. To exit press Ctrl+C")
channel.start_consuming()
